#  Denis Crowdy, modified code from csndsugui by Victor Lazzarini:
# (c) Victor Lazzarini, 2008
#  Free software, licensed by GNU General Public License

import csndsugui
from sugar.activity import activity


class Loopulator(activity.Activity):

 def __init__(self, handle):
    activity.Activity.__init__(self, handle)    

   # colours
    bg = (0x0000, 0x7000, 0xA000)  
    white = (0xFFFF, 0xFFFF, 0xFFFF)
    blue = (0,0, 0xFFFF)

    padding = 4

   # GUI window               
    win = csndsugui.CsoundGUI(self,bg)
    win.csd("loop.csd")
    win.text("Playing Sounds",colour=white)
    bbox = win.box(False)
    #win.button(bbox,"play")
    win.mbutton(bbox,"i1 0 -1", "start")
    win.mbutton(bbox,"i-1 0 -1", "stop")
#    win.button(bbox,"reset")
    win.slider(100, 40, 240, 700, 40,bbox,"tempo", False,linear=True)
    rbox = win.box(False)
    win.mbutton(rbox, "i9 0 -1", "record")
    win.mbutton(rbox, "i-9 0 -1", "stop")
    win.filechooser(rbox,"output_file")

    pbox = []
    for i in range (1,7):
      pbox.append(win.box(False))
      win.filechooser(pbox[i-1],"soundfile%d"% i)
      win.button(pbox[i-1], "mute%d"% i)
      win.button(pbox[i-1], "rev%d"% i)
      win.button(pbox[i-1], "cut%d"% i)
      win.slider(0.5, 0, 1, 120, 40,pbox[i-1],"vol%i" % i, False,linear=True)
      win.slider(0.5, 0, 1, 120, 40,pbox[i-1],"pan%i" % i, False,linear=True)

    osbox  = win.box( False )  # Kick
    osfbox = win.framebox( "One shot samples", False, osbox, blue, padding )
    osf1box = win.framebox( "1", False, osfbox, blue, padding )

#    pbox.append(win.box(False))
    win.filechooser(osf1box, "soundfile7")
    win.mbutton(osf1box, "i3 0 -1", "play")
    win.button(osf1box, "rev7")
    win.slider(0.5, 0, 1, 120, 40,osf1box, "vol7", False, linear=True)

    osf2box = win.framebox( "1", False, osfbox, blue, padding )
    win.filechooser(osf2box, "soundfile8")
    win.mbutton(osf2box, "i4 0 -1", "play")
    win.button(osf2box, "rev8")
    win.slider(0.5, 0, 1, 120, 40,osf2box, "vol8", False, linear=True)

#    compbox = win.box(False)
#    compfbox = win.framebox( "Compressor insert", False, compbox, blue, padding )

#    win.mbutton(compfbox, "i5 0 -1", "on")
#    win.mbutton(compfbox, "i-5 0 -1", "off")
#    win.button(compfbox, "byps")
#    win.slider(-10, -60, 1, 80, 40, compfbox, "Th", False, linear=True)
#    win.slider(1, 1, 20, 80, 40, compfbox, "Rt", False, linear=True)
#    win.slider(0.1, 0.02, 0.5, 80, 40, compfbox, "Att", False, linear=True)
#    win.slider(0.1, 0.02, 1, 80, 40, compfbox, "Rel", False, linear=True)

    gainbox = win.box(False)
    win.slider(5, 0, 10, 240, 40, gainbox, "Gain", False, linear=True)


    win.play()

